﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Windows.Forms;

namespace Newton
{
    class Hud 
    {
        #region "Atrbutos"

        private int velocidadeInical;

        public int angulo;

        public TextBox txtAngulo;

        public DomainUpDown UDAngulo;

        public DomainUpDown UDVelInicial;

        public GroupBox gbEntrada;

        public GroupBox gbSaida;

        public Label lblAngulo;

        public Label lblvelInicial;

        public TextBox txtVelInicial;

        GameWindow Window;

        Player player;

        #endregion

        public Hud(GameWindow Window)
        {

            gbEntrada = new GroupBox();
            gbEntrada.Visible = false;
            gbEntrada.Location = new System.Drawing.Point(10, 490);
            gbEntrada.Text = "Entrada de dados";
            gbEntrada.Font = new System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Bold);
            gbEntrada.BackColor = System.Drawing.Color.CornflowerBlue;
            gbEntrada.Size = new System.Drawing.Size(380, 100);

            gbSaida = new GroupBox();
            gbSaida.Visible = false;
            gbSaida.Location = new System.Drawing.Point(410, 490);
            gbSaida.Text = "Saída";
            gbSaida.Font = new System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Bold);
            gbSaida.BackColor = System.Drawing.Color.CornflowerBlue;
            gbSaida.Size = new System.Drawing.Size(380, 100);

            lblAngulo = new Label();
            lblAngulo.Visible = false;
            lblAngulo.Text = "Ângulo";
            lblAngulo.Font = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold);
            lblAngulo.Location = new System.Drawing.Point(20, 520);
            lblAngulo.BackColor = System.Drawing.Color.CornflowerBlue;
            lblAngulo.AutoSize = true;

            lblvelInicial = new Label();
            lblvelInicial.Visible = false;
            lblvelInicial.Text = "Velocidade Inicial";
            lblvelInicial.Font = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold);
            lblvelInicial.Location = new System.Drawing.Point(20, 550);
            lblvelInicial.BackColor = System.Drawing.Color.CornflowerBlue;
            lblvelInicial.AutoSize = true;
            
            txtAngulo = new TextBox();
            txtAngulo.Visible = false;
            txtAngulo.Location = new System.Drawing.Point(150, 520);
            txtAngulo.BorderStyle = BorderStyle.Fixed3D;
            txtAngulo.Multiline = false;
            txtAngulo.Size = new System.Drawing.Size(100, 90);

            UDAngulo = new DomainUpDown();
            UDAngulo.Visible = false;
            UDAngulo.Location = new System.Drawing.Point(150, 520);
            UDAngulo.BorderStyle = BorderStyle.Fixed3D;
            UDAngulo.Size = new System.Drawing.Size(100, 90);
            for (int i = 90; i >= 0;i--)
            {
                UDAngulo.Items.Add(i);
            }
            UDAngulo.SelectedIndex = 0;
            UDAngulo.Click += new System.EventHandler(anguloClick);

            UDVelInicial = new DomainUpDown();
            UDVelInicial.Visible = false;
            UDVelInicial.Location = new System.Drawing.Point(150, 550);
            UDVelInicial.BorderStyle = BorderStyle.Fixed3D;
            UDVelInicial.Size = new System.Drawing.Size(100, 90);
            for (int i = 1000; i >= 0; i--)
            {
                UDVelInicial.Items.Add(i);
            }
            UDVelInicial.SelectedIndex = 0;
            UDVelInicial.Click += new System.EventHandler(velocidadeClick);
            

            txtVelInicial = new TextBox();
            txtVelInicial.Visible = false;
            txtVelInicial.Location = new System.Drawing.Point(150, 550);
            txtVelInicial.BorderStyle = BorderStyle.Fixed3D;
            txtVelInicial.Multiline = false;
            txtVelInicial.Size = new System.Drawing.Size(100, 90);
           
            
            gbEntrada.Controls.Add(txtAngulo);
            gbEntrada.Controls.Add(lblAngulo);
            gbEntrada.Controls.Add(lblvelInicial);
            gbEntrada.Controls.Add(txtVelInicial);

            Control.FromHandle(Window.Handle).Controls.Add(lblAngulo);
            Control.FromHandle(Window.Handle).Controls.Add(lblvelInicial);
            Control.FromHandle(Window.Handle).Controls.Add(txtAngulo);
            Control.FromHandle(Window.Handle).Controls.Add(UDAngulo);
            Control.FromHandle(Window.Handle).Controls.Add(UDVelInicial);
            Control.FromHandle(Window.Handle).Controls.Add(txtVelInicial);
            Control.FromHandle(Window.Handle).Controls.Add(gbEntrada);
            Control.FromHandle(Window.Handle).Controls.Add(gbSaida);
        }

        private void velocidadeClick(object sender, EventArgs e)
        {
            velocidadeInical = int.Parse(UDVelInicial.Text);
            //MessageBox.Show("" + velocidadeInical);
        }

        private void anguloClick(object sender, EventArgs e)
        {
            if (player != null)
            {
                this.angulo = int.Parse(UDAngulo.Text);
                player.angulo = this.angulo;
                if (this.angulo < 45)
                {
                    player.SetOffset(0, 0);
                    player.currentAnimation = player.baixo;
                    player.currentAnimation.GoToAndStop(0);
                }
                else if (this.angulo >= 45 && this.angulo <= 60)
                {
                    player.SetOffset(-7, 1);
                    player.currentAnimation = player.medio;
                    player.currentAnimation.GoToAndStop(1);
                }
                else
                {
                    player.SetOffset(-4, 1);
                    player.currentAnimation = player.alto;
                    player.currentAnimation.GoToAndStop(2);
                }
            }
        }

        public void Update(GameTime gameTime, KeyboardState keyboardState, Player player)
        {
            this.player = player;
            //if (txtVelInicial.Focused)
            //{
            //    //KeyboardState ns = Keyboard.GetState();
            //    foreach (Microsoft.Xna.Framework.Input.Keys a in keyboardState.GetPressedKeys())
            //    {
            //          txtVelInicial.Text += a.ToString();
                        
            //    }
            //}
            
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (Game1.present_State == Game1.States.LEVEL01)
            {
                gbEntrada.Visible = true;
                txtAngulo.Visible = false;
                UDAngulo.Visible = true;
                UDVelInicial.Visible = true;
                lblAngulo.Visible = true;
                lblvelInicial.Visible = true;
                txtVelInicial.Visible = false;
                gbSaida.Visible = true;
            }

        }
    }
}
